﻿    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class administration_Login : System.Web.UI.Page
{
    private Dictionary<string,string> accounts;
    protected void Page_Load(object sender, EventArgs e)
    {
        accounts = new Dictionary<string, string>();
        accounts.Add("revio", "rev.414");
        /*
         * natty, mariam, tako
         */
        accounts.Add("natty", "nattyU*(0");
        accounts.Add("mariam", "mariamNhy6");
        accounts.Add("tako", "tako777tT");
        accounts.Add("levi", "123");
        accounts.Add("Natty", "natty.c");
    }

    protected void Login_Click(object sender, EventArgs e)
    {
        if (Autenticate(login.Value,pass.Value))
        {
            Response.Redirect("~/administration/default.aspx");
        }
        else
        {

        }
    }

    private bool Autenticate(string username, string password) {
        try
        {
            var res = accounts.Where(a => a.Key == password && a.Value == username).SingleOrDefault();
            if (res.Equals(default(KeyValuePair<string,string>)))
            {
                Session["AdminName"] = username;
                return true;
            }
            return false;
        }
        catch (Exception ex)
        {
            //TODO log ex
            return false;
        }
    }
}